define(function(require, exports){
	var pubjs = require('pubjs');
	var util	= require('util');
	var grid  = require('@base/highGrid');
	var labels = require('modules/labels').labels;
	//财务明细
	var HighGrid = grid.base.extend({
		init: function(config){
			config = pubjs.conf(config, {
					url: 'bill/list',
					param: {
						'IsDeleted': false
					},
					cols: [
						{type:"id", width:60},
						{name:'Date',text:LANG("日期"), width:120,align:'center'},
						{name: 'Type', text: LANG('类型'), render:'renderType', width:100, align:'center'},
						{name: 'Source', text: LANG('来源'),render:'renderSource',width:150, align:'center'},
						{name: 'UserId', text: LANG('目标账户'),render:'',width:150, align:'center'},
					],
					gridName: 'bill',
					metrics: [
						{name: 'RelUserId', text: LANG('来源账户'),render:'',width:150, align:'center'},
						{name: 'CurrencyName', text: LANG('充值货币'),render:'',width:150,align:'center'},
						{name: 'Amount', text: LANG('金额'), render:"renderAmount",width:150,align:'right'},
						{name: 'RestAmount', text: LANG('余额'),width:150,  render:"renderAmount",align:'right'},
						{name: 'Memo', text: LANG('备注'), render:"renderMemo", align:'left'}
					],
					reqType: 'websocket',
					//暂时以Ajax获取
					eventDataLoad: true,
					hasBatch: false,
					hasTab: false,
					hasRefresh: false,
					hasExport: true,
					hasSelect: false,
					hasSwitch: false,
					hasAmount: false,
					auto_load: false
				}
			);
			this.Super('init', arguments);
		},
		renderType: function(idx, val, row, col){
			return {
				'0':LANG("其他"),
				'1':LANG("预充值"),
				'2':LANG("保证金"),
				'3':LANG("返款"),
				'4':LANG("返点"),
				'5':LANG("扣费"),
				'6':LANG("收益")
			}[val];
		},
		renderSource: function(idx, val, row, col){
			return {
				'0':LANG("其他"),
				'1':LANG("人工"),
				'2':LANG("RTB"),
				'3':LANG("在线充值"),
				'4':LANG("快钱"),
				//'5':LANG('广告位监测')
				'5':LANG('Pubright资源扣费')
			}[val]||val;
		}
		,formatSign: function(currencyId){
			var currencyList = pubjs.config("currency"); //获取汇率表
			var currencyObject = {};
			if(currencyId){
				var list = currencyList['all']; //获取汇率表下指定id有关的汇率数据条数
				currencyObject = util.find(list,currencyId,'id');
			}
			return currencyObject.sign;
		},
		// 渲染金额
		renderAmount: function(idx, val, row, col){
			val = util.round0(val, 2);
			// 金额正数字体为绿色，扣费和负数的类型金额为红色
			var status = (row.Type == 5 || /-/g.test(val));
			// var data = LANG("￥")+util.numberFormat(val);
			var data = this.formatSign(row.Currency) + util.numberFormat(val);
			if(status){
				return '<em class="red">'+data+'</em>'
			}else{
				return '<em class="green">'+data+'</em>'
			}
		},
		// 渲染备注
		renderMemo: function(idx, val, row, col){
			if(val){
				return (val == 'null') ? '' : val
			}else{
				return '';
			}
		}
	})
	exports.base = HighGrid;

});